home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Code Resources / Jims CDEFs 1.50 / CDEF Source / source / cdefPopMenu.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  10.2 KB  |  252 lines  |  [TEXT/KAHL]

  1. //------------------------- © 1991-1995 by James G. Stout --------------------------
  2. // File        : cdefPopMenu.h
  3. // Date        : September 1,1991
  4. // Author    : Jim Stout
  5. // Purpose    : popup menu cdef
  6. //            :
  7. //             : Implements all of the features of the Apple popUpMenu CDEF 63.
  8. //             : 
  9. //             : This CDEF is "plug" compatible with the Apple CDEF.
  10. //            :
  11. //             : Any program that successfully uses that CDEF should be able to
  12. //             : use this one.
  13. //             : 
  14. //            : The only feature I have not implemented is drawing of menus
  15. //            :    with command-key equivalents.  The space where that should
  16. //            :    drawn is pre-empted by the "popup symbol".
  17. //            :    The menu will simply draw without the command-key, it will
  18. //            :    be there when you "pop" the menu.
  19. //            :
  20. //             : This CDEF corrects a couple of minor objections I have with
  21. //             : the Apple CDEF. Unlike the Apple CDEF, this CDEF:
  22. //             : 
  23. //             :    1. Behaves the same in both System 6 and 7, including
  24. //            :        support for menus with icons and color.
  25. //             :    2. Only draws its title with Menu colors when
  26. //            :        it is "popped" up (IMHO, this looks better).
  27. //             :    3. It will accept "dynamic" menus created via calls to NewMenu()
  28. //            :        rather than just resource based menus.
  29. //            :    4. Works correctly with popupFixedWidth when the menu is
  30. //            :        narrower than the controlRect.
  31. //            :
  32. //             : I have implemented a few extensions to the Apple CDEF:
  33. //             : 
  34. //             :    1. "Embossed" 3D title
  35. //            :        This is variation code 2.  It results in a control title that
  36. //            :        has an embossed appearance by drawing the title with a white
  37. //            :        shadow.
  38. //            :
  39. //            :        Note that this is a departure from the use of this variation
  40. //            :        in the System 6 popup which used 2 for useCQD - for colored
  41. //            :        menus.  This variation is not defined/doesn't work with the
  42. //            :        System 7 popup CDEF.
  43. //            :
  44. //            :    The following extensions are created by adding an "pseudo
  45. //            :    variation code" to the title width parameter in the controlMax
  46. //            :    field of the control template.
  47. //            :
  48. //            :    The first 4 are additive and can be combined with any other
  49. //            :    "pseudo variation code".
  50. //            :
  51. //             :    2. No item marks
  52. //            :        Calling program can use SetItemMark() to set a mark if needed.
  53. //            :        One use of this would be to create a popup similar to the one
  54. //            :        used in Standard file dialogs.
  55. //            :
  56. //            :    3. An inset frame
  57. //            :        Since a popup menu looks rather odd on 3D dialogs, this
  58. //            :        draws an inset frame for the popup rather than the usual
  59. //            :        raised, drop-shadowed frame.  The grafPort background color
  60. //            :        is used for the popup background because the inset effect
  61. //            :        is lost if the menu background is white.
  62. //            :
  63. //            :    4. Black symbol
  64. //            :        Default behavior with colored menus is to draw the popup symbol
  65. //            :        in the item text color. If you always want black symbols, add
  66. //            :        this "variation code" to controlMax.
  67. //            :
  68. //             :    6. "No DeleteMenu" popups.  Normally, the CDEF calls DeleteMenu
  69. //             :        (per the Apple guidelines) after calling PopupMenuSelect.  This
  70. //             :        causes menu color information to be deleted as well.  If this
  71. //             :        menu color info is supplied via an 'mctb' resource, the CDEF will
  72. //             :        'reload' the colors. If the color info was supplied via 
  73. //             :        SetMCEntries as part of a 'dynamic' menu, there is no easy way
  74. //             :        for the CDEF to recover the colors - hence this variation.
  75. //             :
  76. //            :    The following 4 are NOT additive with each other.  If added together,
  77. //            :    the results are undefined (meaning I didn't test to see what happens).
  78. //            :
  79. //             :    7. "Symbol" only popups
  80. //            :        For "type in" popups often used for Font size selection in
  81. //            :        conjunction with edit text items in dialogs. Additional code
  82. //            :        is needed to implement this, see the demoCDEF program source.
  83. //            :
  84. //            :    8. Popups with no "Symbol"
  85. //            :        No downward pointing triangle is drawn, as in the System 6
  86. //            :        version of CDEF 63.
  87. //            :
  88. //            :    9. Popups with icons only
  89. //            :        This results in a "popup Icon button" effect since only a
  90. //            :        framed icon (of any size or type) is drawn.  Item text and
  91. //            :        the popup symbol are not drawn. 
  92. //            :        Set the control rect to 5 pixels more than the largest icon.
  93. //            :
  94. //            :    10. Popups with centered text
  95. //            :        This results in a "popup text button" effect since the menu
  96. //            :        item text is drawn, centered in the control rect.
  97. //            :
  98. //             : To use, call NewControl as normal, with the following special meanings
  99. //             :    to the parameters listed below. Or set up a ResEdit CNTL template.
  100. //            :    These are exactly the same as Apple's CDEF 63.
  101. //             :
  102. //             : 
  103. //             :    value    : title justification & title text style.
  104. //            :            Justification
  105. //             :
  106. //             :               :     popupTitleLeftJust        = 0x0000
  107. //             :             :     popupTitleCenterJust    = 0x0001
  108. //             :             :     popupTitleRightJust        = 0x00FF
  109. //             :
  110. //            :            Text Styles
  111. //             :
  112. //             :             :     popupTitleBold            = 0x0100
  113. //             :             :     popupTitleItalic        = 0x0200
  114. //             :             :     popupTitleUnderline        = 0x0400
  115. //             :             :     popupTitleOutline        = 0x0800
  116. //             :             :     popupTitleShadow        = 0x1000
  117. //             :             :     popupTitleCondense        = 0x2000
  118. //             :             :     popupTitleExtend        = 0x4000
  119. //             :             :     popupTitleNoStyle        = 0x8000
  120. //             :
  121. //             :    min        : resId of menu to use, even if using popupUseAddResMenu,
  122. //             :                it is best to have a 'dummy' menu resource with no
  123. //             :                items defined.
  124. //             :
  125. //             :    max        : width of title item - from controlRect.left.
  126. //             :            :  0 = no title drawn.
  127. //            :            :
  128. //            :            : add pseudo variation codes to get:
  129. //            : 
  130. //            :            : popupNoMark         = don't use marks on current item.
  131. //            :            : popupBlackSymbol   = always draw black popup symbol
  132. //             :            : popupSymbolOnly    = draw 'popUp symbol' only
  133. //             :            : popupNoSymbol         = don't draw 'popUp symbol'.
  134. //            :            : popupIconOnly      = no symbol and Icon only in control.
  135. //             :            : popupCenterText    = no symbol and text centered in control
  136. //             :            : popupNoDeleteMenu  = don't call DeleteMenu after PopUpMenuSelect
  137. //                                                - call when disposing the control.
  138. //             :
  139. //             :    refCon    : if varCode of popupUseAddResMenu, put the ResType
  140. //             :              in the refCon field of the control.
  141. //
  142. //             :    procId    : 1600 + varCode  (1101 * 16) + varCode
  143. //             :            : varCodes:
  144. //             :                popupFixedWidth        = 0x0001
  145. //            :                ctl3D                = 0x0002
  146. //             :                popupUseAddResMenu    = 0x0004
  147. //             :                popupUseWFont        = 0x0008
  148. //             
  149. //----------------------------------------------------------------------------------
  150.  
  151. #ifndef popupTitleLeftJust        // should be in Controls.h
  152.  
  153. //----------------------------------------------------------------------------------
  154. // special meanings for contrlValue field
  155. //----------------------------------------------------------------------------------
  156.  
  157. #define popupTitleLeftJust        0x0000
  158. #define popupTitleCenterJust    0x0001
  159. #define popupTitleRightJust        0x00FF
  160. #define popupTitleBold            0x0100
  161. #define popupTitleItalic        0x0200
  162. #define popupTitleUnderline        0x0400
  163. #define popupTitleOutline        0x0800
  164. #define popupTitleShadow        0x1000
  165. #define popupTitleCondense        0x2000
  166. #define popupTitleExtend        0x4000
  167. #define popupTitleNoStyle        0x8000
  168.  
  169. //----------------------------------------------------------------------------------
  170. // variation codes
  171. //----------------------------------------------------------------------------------
  172.  
  173. #define popupFixedWidth            0x0001
  174. #define ctl3D                    0x0002
  175. #define popupUseAddResMenu        0x0004
  176. #define popupUseWFont            0x0008
  177.  
  178. #endif
  179.  
  180. //----------------------------------------------------------------------------------
  181. // pseudo variation codes - add to title width in contrlMax field
  182. //----------------------------------------------------------------------------------
  183.  
  184. #define popupNoTitle            0x0000
  185. #define popupNoMark                0x0100
  186. #define popupInsetFrame            0x0200
  187. #define popupBlackSymbol        0x0400
  188. #define popupSymbolOnly            0x0800
  189. #define popupNoSymbol            0x1000
  190. #define popupIconOnly            0x2000
  191. #define popupCenterText            0x4000
  192. #define popupNoDeleteMenu        0x8000
  193.  
  194. #define        DOT                0xA5    // item marks used if not using popupNoMark
  195. #define        CHECKMARK        0x12
  196. #define        ELLIPSIS        0xC9
  197. #define        SHADOW            3        // extra space needed for drop shadow box
  198.  
  199. //----------------------------------------------------------------------------------    
  200. // Note:  This is NOT the Apple struct of the same name.  Only the first 2 
  201. //            elements are documented by Apple, I left them the same in this
  202. //            structure, but everything after mId is unique to this CDEF.
  203. //----------------------------------------------------------------------------------
  204.  
  205. typedef struct{
  206. MenuHandle    mHandle;                // handle to the menu         
  207. short        mId;                    // resource id of menu
  208.  
  209. Rect        rTitle;                    // rect for title
  210. Rect        rItem;                    // rect for popup
  211. Rect        rIcon;                    // rect for icon
  212. short        tJust;                    // title justification & style flag    
  213. short        tWid;                    // requested title width
  214. short        varCode2;                // extra variations
  215. short        symWid;                    // extra space needed for popup symbol    
  216. short        symHt;                    // symbol height
  217. short        vDraw;                    // Title & Item draw v point
  218. short        hTitle;                    // Title draw h point
  219. short        hItem;                    // Item draw h point
  220. short        txFont;
  221. short        txSize;
  222. short        osVers;                    // for later reference
  223. SignedByte    hMenuState;                // thanks Gord!
  224. Boolean        hasColorQD;                // ditto
  225. Boolean        relMenuRes;
  226. }popUpPrivateData,**popUpPrivateDataH;
  227.  
  228. //----------------------------------------------------------------------------------
  229. //    Function prototypes
  230. //----------------------------------------------------------------------------------
  231.  
  232. static void        doInit                (ControlHandle, short);
  233. static void        doDisp                (ControlHandle, short);
  234. static void        doDraw                (ControlHandle, short);
  235. pascal void     drawControl         (short depth, short dFlags, GDHandle theDevice,
  236.                                         long userData);
  237. static void        doPopUp                (ControlHandle, short);
  238.  
  239. static void        drawSymbol            (Rect, short, short);
  240. static void        drawPopupFrame        (Rect *);
  241. static void     getRects            (ControlHandle, Boolean);
  242. static void        resizePopup            (ControlHandle, short);
  243. static pascal void myCalcMenuSize    (MenuHandle);
  244. static void        patchCalcMenuSize    (short);
  245. static void        getMenuColors        (short, short, RGBColor *, RGBColor *);
  246. static void        setMenuColors        (short);
  247. static Boolean    setFont                (GrafPtr, short *, short *, short, Boolean);
  248. static void        restoreFont            (GrafPtr, short,     short,     short);
  249. static void     getIconSize            (short, Rect *);
  250. static void     plotAnIcon            (short, Rect *, short, short,
  251.                                         Boolean, Boolean, Boolean);
  252. extern Boolean     hasColorQD            (void);